﻿using System.Collections.Generic;
using System.Windows.Media;

namespace ConnectedComponents
{
    public struct Span
    {
        public int StartX;
        public int EndX;
        public int Y;
        public Color Color;

        public bool IntersectsWith(Span relativeTo)
        {
            return Color == relativeTo.Color 
                && !(StartX > relativeTo.EndX || EndX < relativeTo.StartX);
        }
    }

    public class SpanList : List<Span> 
    {
        public void UnionWith(SpanList otherSpans)
        {
            this.AddRange(otherSpans);
        }

        public bool IntersectsWith(Span relativeTo)
        {
            foreach (var span in this)
            {
                if (span.IntersectsWith(relativeTo))
                {
                    return true;
                }
            }
            return false;
        }
    }
}
